﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ModelLayer;

namespace ViewLayer.UserConfiguration
{
    public partial class UserConfigurationForm : Form
    {
        MedAgendaEntities entities = new MedAgendaEntities();

        public UserConfigurationForm()
        {
            InitializeComponent();
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            if (txtFullName.Text.Equals(string.Empty) || txtMobile.Text.Equals(string.Empty) || txtDegree.Text.Equals(string.Empty)
                || txtCountry.Text.Equals(string.Empty) || txtProvince.Text.Equals(string.Empty) || txtCity.Text.Equals(string.Empty))
            {
                MessageBox.Show(null, "Llenar los campos obligatorios.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                User_ user = new User_();
                user.Version_ = 1;
                user.OID_ = Guid.NewGuid();
                user.UserName_ = txtFullName.Text;
                user.PartnershipName_ = txtPartnershipName.Text;
                user.Degree_ = txtDegree.Text;
                user.MobileNumber_ = txtMobile.Text;
                user.TelephoneNumber_ = txtPhoneNumber.Text;
                user.Status_ = "activo";
                user.CreationTime_ = DateTime.Now;
                user.LastLoginTime_ = DateTime.Now;
                user.Country_ = txtCountry.Text;
                user.City_ = txtCity.Text;
                user.Province_ = txtProvince.Text;
                user.Address_ = txtAddress.Text;
                user.Referrer_ = txtReferrer.Text;
                entities.User_.AddObject(user);
                entities.SaveChanges();
                this.Close();
            }
        }
    }
}
